<template>
  <div class="container">
    <div>
      <el-row :gutter="12">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="开始日期：">
              <el-date-picker
                v-model="form.StartDate"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="结束日期：">
              <el-date-picker
                v-model="form.EndDate"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form" style="float: left">
            <el-button size="mini" type="primary" @click="getDataPlan"
              >查 询</el-button
            >
            <el-button size="mini" type="success" @click="exportExcel"
              >导 出</el-button
            >
          </el-form>
        </el-col>
      </el-row>
    </div>
    <el-table
      v-loading="loading"
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
    >
      <!-- <el-table-column
        prop="ID"
        label="序号"
        align="center"
      ></el-table-column> -->
      <el-table-column
        prop="LICENSE_PLATE"
        label="车牌号"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="CLIENT_NAME"
        label="区域"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="COMPANY"
        label="所属公司"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="RESULT"
        label="结果"
        align="center"
      ></el-table-column>
      <!-- <el-table-column
        prop="SCORE"
        label="准确率"
        align="center"
      ></el-table-column> -->
      <el-table-column
        prop="UPTIME"
        label="识别日期"
        align="center"
      ></el-table-column>
      <el-table-column label="查看照片" width="150px" align="center">
        <template slot-scope="scope">
          <el-image
            style="width: 45px; height: 45px; margin-top: 5px"
            :src="scope.row.URL1"
            @click="bigImage(scope.row)"
          >
            <div slot="error" class="image-slot" style="margin-top: 10px">
              <i class="el-icon-picture-outline"></i>
            </div>
          </el-image>
        </template>
      </el-table-column>
      <!-- <el-table-column label="车后照片" width="150px" align="center">
        <template slot-scope="scope">
          <el-image
            style="width: 45px; height: 45px; margin-top: 5px"
            :src="scope.row.URL2"
            @click="bigImage2(scope.row)"
          >
            <div slot="error" class="image-slot" style="margin-top: 10px">
              <i class="el-icon-picture-outline"></i>
            </div>
          </el-image>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="操作" width="150">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleEdit(scope.$index, scope.row)"
            >明细</el-button
          >
          <el-button
            type="text"
            @click="handleShowMap(scope.$index, scope.row)"
            >地图</el-button
          >
        </template>
      </el-table-column> -->
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>

    <!-- 图片放大 -->
    <el-dialog
     v-dialogDrag
      title="报警图片展示"
      :visible.sync="showBigDialogVisible"
      width="22.646vw"
      height="22.646vw"
      :close-on-click-modal="false"
    >
      <img :src="itemImageSrc" style="height: 100%; width: 100%" alt="图片丢失了" />
      <div style="margin:10px; text-align:center">
      <el-button  type="primary" round   @click="setActiveItem(0)" > 1</el-button>
      <el-button  type="primary"  round   @click="setActiveItem(1)" > 2</el-button>
      </div>
    </el-dialog>
    <!-- <el-dialog
      title="图片展示"
      :visible.sync="showBigDialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <el-image style="width: 100%; height: 100%" :src="srcBig"></el-image>
    </el-dialog> -->
  </div>
</template>
<script>
import '@/assets/css/common.css'
import { formatDate } from '@/common/js/date.js'
import export2Excel from '@/utils/exportExcel/index.js'
export default {
  data () {
    return {
      loading: false,
      currentPage: 1, // 初始页
      pageSize: 10, //    每页的数据
      form: {
        radioData: '日',
        valueDay: '',
        valueDaySelect: '',
        valueMonth: '',
        valuePointID: '',
        valueType: '',
        typeDatePicker: 'date',
        formatDatePicker: 'yyyy-MM-dd',
        queryType: 1,
        queryTypeList: [{
          value: 1,
          label: '按日期查询'
        }, {
          value: 2,
          label: '按月份查询'
        }],
        StartDate: formatDate(new Date(new Date() - 3600 * 1000 * 24 * 30), 'yyyy-MM-dd'),
        EndDate: formatDate(new Date(), 'yyyy-MM-dd 23:59:59'),
      },
      itemImageSrc: '',
      imageList: [],
      selectPointData: [],
      tableData: [],
      dialogDetail2Title: '',
      dialogDetail2Show: false,
      dialogDetail2Data: [],
      dialogDetail3Title: '',
      dialogDetail3Show: false,
      dialogDetail3Data: [],
      dialogDetail4Title: '',
      dialogDetail4Show: false,
      dialogDetail4Data: [],
      dialogDetail5Title: '',
      dialogDetail5Show: false,
      dialogDetail5Data: [],
      showBigDialogVisible: false,
    }
  },
  created () {
    this.form.valueDay = formatDate(new Date(new Date() - 3600 * 1000 * 24), 'yyyy-MM-dd')
    this.form.valueMonth = formatDate(new Date(), 'yyyy-MM')
    this.getDataPlan()
  },
  methods: {
    // handleShowMap (index, row) {
    //   this.$router.push({ name: 'RouteStatisticsMap', params: { data: row } })
    // },
    // async getDataReality () {
    //   this.loading = true;
    //   var url = 'RubbishVehicle/GetRubbishHistoryVehicleCCApi?TYPE=0&WORKDATE=' + this.form.valueDay + '&CLIENT_NO=' + localStorage.getItem('CLIENT_NO')
    //   const { data } = await this.$Http.get(url)
    //   var vid = data[0].车辆编号;
    //   var arrayPointInfoOfCar = [];
    //   var arrayDataReality = [];
    //   data.forEach(element => {
    //     if (vid != element.车辆编号) {
    //       arrayDataReality.push({ 'VID': arrayPointInfoOfCar[0].车辆编号, 'NAME': arrayPointInfoOfCar[0].车辆名称, 'DATAREAL': arrayPointInfoOfCar, 'DATACOUNTREAL': arrayPointInfoOfCar.length })
    //       vid = element.车辆编号;
    //       arrayPointInfoOfCar = [];
    //     }
    //     arrayPointInfoOfCar.push(element);
    //   });
    //   this.getDataPlan(arrayDataReality)
    // },
    // 切换图片
    setActiveItem:function(index){
      if (index == 0) {
        this.itemImageSrc =this.imageList[0]
      }
      else if (index == 1) {
         this.itemImageSrc =this.imageList[1]
      }
      else if (index == 2) {
         this.itemImageSrc =this.imageList[2]
      }
    },
    // 放大图片
    bigImage (row) {
      this.imageList = row.arrImage
      if (this.imageList.length > 0) {
        this.itemImageSrc = this.imageList[0]
        this.showBigDialogVisible = true
      }
    },
    // 放大图片
    bigImage2 (row) {
      this.srcBig = row.URL2
      this.showBigDialogVisible = true
    },
    async getDataPlan () {

      //http://111.160.78.62:9930/Cityscapeapi/Vehicle/GetVehicleAIInfoVehicle?StartTime=2022-12-01&EndTime=2022-12-31&client_no=00000
      var url = 'Vehicle/GetVehicleAIInfoVehicleZT?client_no=' + localStorage.getItem('CLIENT_NO') + '&StartTime=' + this.form.StartDate + '&EndTime=' + this.form.EndDate
      const { data } = await this.$Http.get(url)
      // 原始数据
      this.tableData = data
      this.tableData.forEach(element => {
        // if (element.RESULT === "脏") {
        //   element.RESULT = '撒漏'
        // } else {
        //   element.RESULT = '未撒漏'
        // }
        element.arrImage = [element.URL1, element.URL2]
        // element.SCORE =Number(element.SCORE).toFixed(3) 
        // element.SCORE = element.SCORE.substring(0,5)
        element.CLIENT_NAME = '东丽区'
      });
    },
    // 导出Excel
    exportExcel () {
      const excelName = '收运点位分析'
      var tHeader = ['车辆名称', '计划收运点位数', '实际收运点位数', '作业率']
      var filterVal = ['NAME', 'DATACOUNTPLAN', 'DATACOUNTREAL', 'WORKRATE']
      export2Excel(tHeader, filterVal, this.tableData, excelName)
    },
    handleEdit (index, row) {
      this.dialogDetail3Title = '垃圾点明细'
      this.dialogDetail3Data = row.DATAREAL
      console.log(row.DATAREAL)
      this.dialogDetail3Show = true
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange (size) {
      this.pageSize = size
      console.log(this.pageSize)
    }
  }
}
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  min-width: 400px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
/* 弹出框 */
.el-dialog {
  background: #ccd8e7;
  padding: 0px 10px 10px;
}
.el-dialog__title {
  color: #15428b;
  font-size: 16px;
  font-weight: 600;
}
.el-dialog__body {
  background: #dfe8f6;
  border: 1px solid #99bbe8;
}
.el-dialog__footer {
  padding: 10px 0px;
}
</style>
